package com.raymond.cmpp.client.queue;

import com.raymond.cmpp.client.thread.AsyncTaskHandleThread;
import com.raymond.cmpp.common.msg.request.DeliverRequestMessage;
import com.raymond.queue.FileQueue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.TimeUnit;

/**
 * 状态报告上行持久化队列
 *
 * @author :  raymond
 * @version :  V1.0
 * @date :  2021-08-13 09:58
 */
public class DeliverQueue {

    private final static Logger logger = LoggerFactory.getLogger(DeliverQueue.class);

    private static final String TOPIC = "deliver";

    private static FileQueue<DeliverRequestMessage> fileQueue;

    public static FileQueue<DeliverRequestMessage> getFileQueue() {
        if (fileQueue == null) {
            synchronized (DeliverQueue.class) {
                if (fileQueue == null) {
                    try {
                        fileQueue = FileQueue.ordinary(DeliverRequestMessage.class, TOPIC);
                    } catch (Exception e) {
                        try {
                            logger.warn("文件队列创建失败,重新创建中,异常原因:{}", e.getMessage());
                            TimeUnit.SECONDS.sleep(30);
                            fileQueue = FileQueue.ordinary(DeliverRequestMessage.class, TOPIC);
                        } catch (Exception ex) {
                            logger.warn("状态报告文件队列创建失败,:", e);
                        }
                    }
                }
            }
        }
        return fileQueue;
    }
}
